package dk.itu.amds.broker.data;

import java.util.HashMap;
import java.util.Map;

public class BrokerDB {
	public static Map<Integer, Float> accounts = new HashMap<Integer, Float>() {};
	
	public static void initialize() {
		accounts.put(1, 2000f);
		accounts.put(2, 15000f);
		accounts.put(3, 9950f);
		accounts.put(4, 12000f);
	}
	
	public static boolean validate(int fromAccountId, int toAccountId, float amount) {
		float fromAccountSaldo;
		
		if (!accounts.containsKey(fromAccountId) || !accounts.containsKey(toAccountId)){
			return false;			
			
		}
	
		fromAccountSaldo = accounts.get(fromAccountId);
		
		if (fromAccountSaldo < amount){
			return false;
		}
	/*
		toAccountSaldo = accounts.get(toAccountId);
		
		fromAccountSaldo -= amount;
		toAccountSaldo += amount;
		
		accounts.put(fromAccountId, fromAccountSaldo);
		accounts.put(toAccountId, toAccountSaldo);
	*/
		
		return true;
	}
	
	public static void transfer(int fromAccountId, int toAccountId, float amount){
		float fromAccountSaldo, toAccountSaldo;
		
		fromAccountSaldo = accounts.get(fromAccountId);
		toAccountSaldo = accounts.get(toAccountId);
		
		fromAccountSaldo -= amount;
		toAccountSaldo += amount;
		
		accounts.put(fromAccountId, fromAccountSaldo);
		accounts.put(toAccountId, toAccountSaldo);

	}
	
	public static float getAccountSaldo(int accountId) {
		return accounts.get(accountId);
	}
}
